#include <iostream>
#include <vector>
#include <string>

using namespace std;

class Solution {
public:
	int romanToInt(string s) {
		vector<int> singles;
		for(int i=0;i<s.length();++i){
			singles.push_back(singleToInt(s[i]));
		}
		for(int i=0;i<singles.size()-1;++i){
			if(singles[i]<singles[i+1])
				singles[i]=-1*singles[i];
		}
		int total=0;
		for(int i=0;i<singles.size();++i)
			total+=singles[i];
		return total;
	}
private:
	int singleToInt(char c){
		if(c=='I')
			return 1;
		if(c=='V')
			return 5;
		if(c=='X')
			return 10;
		if(c=='L')
			return 50;
		if(c=='C')
			return 100;
		if(c=='D')
			return 500;
		if(c=='M')
			return 1000;
	}
};

int main(){
	Solution s;
	string str;
	while(cin>>str){
		cout<<s.romanToInt(str)<<endl;
	}
}